package com.hmdp.config;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.hmdp.properties.SnowflakeProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class IdConfig {

    private final SnowflakeProperties properties;

    public IdConfig(SnowflakeProperties properties) {
        this.properties = properties;
    }

    @Bean
    public Snowflake snowflake() {
        return IdUtil.getSnowflake(properties.getWorkerId(), properties.getDatacenterId());
    }
}
